﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;

/// <summary>
/// scoreDao 的摘要说明
/// </summary>
public class ScoreDao
{
    //获取数据库连接串
    private static string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;

    /// <summary>
    /// 
    ///获取Info表中所有的记录
    /// </summary>
    /// <returns></returns>
    public static List<ScoreInfo> FindAll(int start, int num)
    {
        List<ScoreInfo> data = new List<ScoreInfo>();
        MySqlConnection conn = new MySqlConnection(connStr);
        try
        {
            conn.Open();
            string sql = "select tb_score.id,tb_student.student_name,tb_course.course_name,score "
                + " from tb_score,tb_student,tb_course "
                + " where tb_score.student_num = tb_student.student_num and tb_score.course_num = tb_course.course_num "
                + " limit " + start + "," + num;
            //构建一个sql的命令
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            //获取数据访问的游标
            MySqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                ScoreInfo scoreInfo = new ScoreInfo();
                scoreInfo.Id = Convert.ToInt64(rdr["id"]);
                scoreInfo.StudentName = Convert.ToString(rdr["student_name"]);
                scoreInfo.CourseName = Convert.ToString(rdr["course_name"]);
                scoreInfo.Score = Convert.ToString(rdr["score"]);

                data.Add(scoreInfo);
            }
            rdr.Close();
        }
        catch (MySqlException ex)
        {
            Debug.WriteLine(ex.Number + ":" + ex.Message);
            throw (ex);
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }

        return data;
    }


    
}